<!--
 * @Date: 2023-03-24 10:37:25
 * @LastEditTime: 2023-04-28 15:09:35
-->
<template>
  <a-config-provider :locale="locale">
    <router-view v-if="isActive" />

    <langSelect
      ref="selectRef"
      :query="query"
      @getData="setData"
      @selectChange="selectChange"
    />
  </a-config-provider>
</template>

<script setup>
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN';
import { getCurrentInstance, onMounted, nextTick, ref } from 'vue';

dayjs.locale('zh-cn');
const locale = zhCN;

const instance = getCurrentInstance();
const { proxy } = instance;

onMounted(() => {});

/**
 * 国际化语言=====开始
 */

// 请求参数
const query = ref({ account_id: 1, project_name: 'cpcps' }),
  // 页面路由是否响应
  isActive = ref(false),
  // 接收SDK返回数据
  setData = () => {
    const { details, selectValue } = proxy.$refs.selectRef;

    isActive.value = true;
    instance.appContext.config.globalProperties.$details = details;
    instance.appContext.config.globalProperties.$language = selectValue;
  },
  // 语言下拉框变更处理
  selectChange = () => {
    isActive.value = false;
    setTimeout(() => {
      setData();
      isActive.value = true;
    }, 0);
  };
  
/**
 * 国际化语言=====结束
 */
</script>
